<template>
	<view class="page">
		<view class="top-account-information">
			<image class="bg-image" src="../../static/images/walletbjy@2x.png" mode=""></image>
			<view class="account-information">
				<view class="top-info">
					<view class="title">账户余额（元）</view>
					<view class="btn" @click="withdrawals">申请提现</view>
				</view>
				<view class="money">{{ moneyInfo.balance || 0 }}</view>
				<view class="bottom-info">
					<view class="left-bottom-item">
						<view>{{ moneyInfo.todayIncome || 0 }}</view>
						<view>今日收入（元）</view>
					</view>
					<view class="right-bottom-item">
						<view>{{ moneyInfo.cumulativeIncome || 0 }}</view>
						<view>累计收入（元）</view>
					</view>
				</view>
			</view>
		</view>

		<u-sticky>
			<view class="tab-list">
				<view class="tab-item" v-for="(item, index) in tabs" :key="index" @click="tabChange(item, index)">
					<view class="value" :class="current == index ? 'active' : ''">{{ item.name }}</view>
					<view class="line" v-if="current == index"></view>
				</view>
			</view>
		</u-sticky>
		<view class="money-list">
			<view class="money-item" v-for="(item, index) in list" :key="index">
				<view class="top-info" v-if="current == 0">
					<view class="title">{{ item.remark }}</view>
					<view class="value" v-if="item.changeType == 1">+{{ item.balance }}</view>
					<view class="value" style="color:#FF290B" v-else>-{{ item.balance }}</view>
				</view>
				<view class="top-info" v-if="current == 1">
					<view class="title">{{ item.status | statusFilter }}</view>
					<view class="value">-{{ item.amount }}</view>
				</view>
				<view class="create-time">{{ item.createTime }}</view>
				<view class="create-time" style="color: #FF290B;margin-top: 6rpx;" v-if="current == 1">拒绝原因：{{ item.remarks || '--' }}</view>
			</view>
		</view>
	</view>
</template>

<script>
import { accountInfo, accountDetail, getEscortWithdrawalRecord } from '@/apis/request.js';
export default {
	data() {
		return {
			current: 0,
			tabs: [
				{
					name: '余额明细'
				},
				{
					name: '提现记录'
				}
			],
			list: [],
			pageNo: 1,
			total: 0,
			moneyInfo: {}
		};
	},
	filters: {
		statusFilter(status) {
			if (status == 0) {
				return '待审核';
			} else if (status == 3) {
				return '提现完成';
			} else if (status == 99) {
				return '提现拒绝';
			}
		}
	},
	onLoad() {
		this.getList();
	},
	onShow() {
		this.moneyInfos();
		this.pageNo = 1;
		this.getList();
		uni.$on('attendantMoneyChange', () => {
			this.moneyInfos();
		});
	},
	onReachBottom() {
		if (this.total > this.list.length) {
			this.pageNo++;
			this.getList();
		}
	},
	methods: {
		//账户信息
		moneyInfos() {
			accountInfo().then(res => {
				// console.log('账户信息',res)
				this.moneyInfo = res;
			});
		},

		// 余额/提现记录明细
		getList() {
			if (this.current == 0) {
				accountDetail({
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					this.total = res.total;
					if (this.pageNo == 1) {
						this.list = res.records;
					} else {
						this.list = this.list.concat(res.records);
					}
				});
			} else {
				getEscortWithdrawalRecord({
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					this.total = res.total;
					if (this.pageNo == 1) {
						this.list = res.records;
					} else {
						this.list = this.list.concat(res.records);
					}
				});
			}
		},
		tabChange(item, index) {
			this.current = index;
			this.pageNo = 1;
			this.getList();
		},
		withdrawals() {
			uni.navigateTo({
				url: `/pages/MinePages/spread/withdrawals?type=0`
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	background-color: #f2f2f2ff;
	height: 100%;
	min-height: 100vh;

	.top-account-information {
		width: 750rpx;
		height: 448rpx;
		position: relative;
		color: #fff;
		background-color: #fff;

		.bg-image {
			width: 670rpx;
			height: 380rpx;
			flex-shrink: 0;
			margin: 30rpx 40rpx 34rpx 40rpx;
		}

		.account-information {
			.top-info {
				.title {
					position: absolute;
					top: 140rpx;
					left: 293rpx;
				}
				.btn {
					position: absolute;
					right: 62rpx;
					top: 144rpx;
					width: 130rpx;
					height: 54rpx;
					line-height: 54rpx;
					border-radius: 28rpx;
					border: 2rpx solid #fff;
					font-size: 24rpx;
					text-align: center;
				}
			}
			.money {
				position: absolute;
				text-align: center;
				width: 750rpx;
				// right: 276rpx;
				top: 186rpx;
				font-size: 100rpx;
			}
			.bottom-info {
				font-size: 24rpx;
				display: flex;
				align-items: center;
				text-align: center;
				justify-content: space-around;

				.left-bottom-item {
					position: absolute;
					left: 178rpx;
					bottom: 68rpx;
				}
				.right-bottom-item {
					position: absolute;
					right: 178rpx;
					bottom: 68rpx;
				}
			}
		}
	}

	.tab-list {
		margin-top: 20rpx;
		background-color: #fff;
		width: 750rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-around;
		.tab-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: 28rpx;
			color: #999999;

			.value {
				padding: 30rpx 0 24rpx 0;
			}
			.line {
				width: 28rpx;
				height: 6rpx;
				border-radius: 3rpx;
				background: #32C59A;
			}
		}
		.active {
			font-size: 30rpx;
			color: #020202;
		}
	}

	.money-list {
		background-color: #fff;
		.money-item {
			border-top: 2rpx solid #ededed;
			padding: 30rpx;
			.top-info {
				display: flex;
				align-items: center;
				justify-content: space-between;
				.title {
					font-size: 30rpx;
				}
				.value {
					font-size: 32rpx;
					margin-top: 10rpx;
				}
			}
			.create-time {
				font-size: 22rpx;
				color: #999999;
			}
		}
	}
}
</style>
